-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronously update internal sockets length so http.Agent pooling is used #300
Conversation
🦋 Changeset detectedLatest commit: 4650f93 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I updated the reproduction in #299 to include more examples and when I install
|
Fixes #299
This is a bit of a hack, but I went with this approach because it allows for all of the native socket pooling behavior in
http.Agent
to be used andconnect()
to keep it's async signature.The tradeoff is manipulating the internal
sockets
dictionary which isreadonly
(according to@types/node
) and therefore needs a lot of@ts-expect-error
comments. An alternative approach would require overwriting theaddRequest()
method with custom pooling code.The approach in this PR works by synchronously adding a fake socket to the pool so
this.sockets[originName].length
is accurate before any other requests are added. Then the socket is removed directly afterconnect()
finishes.